#include "SdkMotionDetectRecord.h"

#define DEF_TAG "MDRecord"

Com_void SdkMotionDetectRecord_Start(Com_void)
{
    tuya_ipc_start_storage(E_ALARM_SD_STORAGE);
}

Com_void SdkMotionDetectRecord_Stop(Com_void)
{
    tuya_ipc_stop_storage(E_ALARM_SD_STORAGE);
}

Com_void Ext_SdkMotionDetectRecord_SetMode(Com_s32 mode)
{
#if CMAKE_SUPPORT_SD_RECORD
    static Com_u8 event_flag = EVENT_RECORD_UNKNOW;

    if (Ext_InComFile_Access(DEF_DP_EVENT_RECORD) == DEF_COM_FILE_NOT_EXIST)
    {
        return;
    }

    if ((Ext_TuyaMD_GetFlag() == DEF_COM_TRUE) && (mode == START_EVENT_RECORD))
    {
        if ((SS_WRITE_MODE_EVENT == tuya_ipc_ss_get_write_mode()) && (E_STORAGE_STOP == tuya_ipc_ss_get_status()))
        {
            SdkMotionDetectRecord_Start();
            event_flag = START_EVENT_RECORD;
        }
    }

    if ((mode == STOP_EVENT_RECORD) && (event_flag == START_EVENT_RECORD))
    {
        SdkMotionDetectRecord_Stop();
        event_flag = STOP_EVENT_RECORD;
    }
#endif
}
